﻿@model WeddingEventManagementApp.Models.Location_VM

@{
    ViewBag.Title = "Edit " + Model.Name;
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="twelve columns">
<h3 class="blue-head">Edit Location</h3>

@using (Html.BeginForm()) 
{
    <div>
        @Html.ValidationSummary(true,"There has been an Error processing your request", new { @class = "no-bullet alert-box alert" })
    </div>
    
    @Html.HiddenFor( model => model.Lat)
    @Html.HiddenFor( model => model.Lng)
    
    <div class="twelve columns">
        <div class="row">
            <div class="two columns">
                <label class="right inline">Location Name: *</label>
            </div>
            <div class="six columns">
                @Html.EditorFor(model => model.Name)
            </div>
            <div class="four columns">
                @Html.ValidationMessageFor(model => model.Name)
            </div>
        </div>
        
        <div class="row">
            <div class="two columns">
                <label class="right inline">Address: *</label>
            </div>
            <div class="six columns">
                <div class="row">
                    <div class="twelve columns">
                        @Html.EditorFor(model => model.StreetAddress)
                    </div>
                    <div class="six columns">
                        @Html.TextBoxFor(model => model.City, new {@class="cmbx", placeholder="City"})
                    </div>
                    <div class="three columns">
                        @Html.DropDownListFor(model => model.Province,
                                from Province type in Enum.GetValues(typeof(Province))
                                select new SelectListItem() { Text = type.ToString(), Value = ((int)type).ToString() }, new { @class="ddl" })
                    </div>
                    <div class="three columns">
                        @Html.TextBoxFor(model => model.PostalCode, new { placeholder = "Postal Code" })
                    </div>
                </div>

            </div>
            <div class="four columns">
                @Html.ValidationMessageFor(model => model.StreetAddress)
                @Html.ValidationMessageFor(model => model.City)
                @Html.ValidationMessageFor(model => model.PostalCode)
            </div>
        </div>

        <div class="row">
            <div class="two columns">
                <label class="right inline">Location Type: *</label>
            </div>
            <div class="six columns">
                @Html.DropDownListFor(m => m.Type, (IEnumerable<SelectListItem>)ViewBag.DropdownTypes, new { @class = "ddl" })
            </div>
            <div class="four columns">
                @Html.ValidationMessageFor(model => model.Type)
            </div>
        </div>

        <br>

        

        <div class="row">
            <div class="two columns">
                <label class="right inline">Phone:</label>
            </div>
            <div class="six columns">
                @Html.TextBoxFor(model => model.ContactPhone, new {placeholder="Contact Phone"})
            </div>
            <div class="four columns">
                @Html.ValidationMessageFor(model => model.ContactPhone)
            </div>
        </div>

        <div class="row">
            <div class="two columns">
                <label class="right inline">Email:</label>
            </div>
            <div class="six columns">
                @Html.TextBoxFor(model => model.ContactEmail, new {placeholder="Contact Email"})
            </div>
            <div class="four columns">
                @Html.ValidationMessageFor(model => model.ContactEmail)
            </div>
        </div>

        <div class="row">
            <div class="two columns">
                <label class="right inline">Website:</label>
            </div>
            <div class="six columns">
                @Html.TextBoxFor(model => model.Website, new { placeholder="Website Address"})
            </div>
            <div class="four columns">
                @Html.ValidationMessageFor(model => model.Website)
            </div>
        </div>

        <div class="row">
            <div class="two columns">
                <label class="right inline">Contact Person:</label>
            </div>
            <div class="six columns">
                @Html.EditorFor(model => model.ContactName)
            </div>
            <div class="four columns">
                @Html.ValidationMessageFor(model => model.ContactName)
            </div>
        </div>

        <div class="row">
            <div class="two columns">
                <label class="right inline">Venue Capacity:</label>
            </div>
            <div class="six columns">
                @Html.EditorFor(model => model.Capacity)
            </div>
            <div class="four columns">
                @Html.ValidationMessageFor(model => model.Capacity)
            </div>
        </div>

        <div class="row">
            <div class="two columns">
                <label class="right inline">Notes:</label>
            </div>

            <div class="six columns">
                @Html.TextAreaFor(model => model.Notes, new { @rows = "7" })
            </div>
            <div class="four columns">
                @Html.ValidationMessageFor(model => model.Notes)
            </div>
        </div>

        <div class="ten columns offset-by-four">
            <input type="submit" value="Save Location" class="button text-center" />
        </div>
    </div>
}

<div>

@section Scripts {
    <script src="~/Scripts/jquery.maskedinput-1.3.js"></script>
    @Scripts.Render("~/bundles/jqueryval")
    <script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=true"></script>
    <script src="~/Scripts/gmaps.js"></script>
    <script>
        $(document).ready(function () {
            $(".ddl").kendoDropDownList();

            $(".cmbx").kendoComboBox({
                dataSource: {
                    type: "json",
                    transport: {
                        read: "/Client/Cities"
                    }
                }
            });

            $('#PostalCode').mask("a9a 9a9");

            $('form').submit(function (e) {
                e.preventDefault();
                var addr = $("#StreetAddress").val() + ", " + $("#City").val() + " " + $('#Province option:selected').text() + " " + $("#PostalCode").val();
                GMaps.geocode({
                    address: addr,
                    callback: function (results, status) {
                        if (status == 'OK') {
                            var latlng = results[0].geometry.location;
                            $('#Lat').val(latlng.lat());
                            $('#Lng').val(latlng.lng());

                            $('form').unbind("submit");
                            $('form').submit();
                        }
                        else {
                            alert("Problem Finding Address");
                        }
                    }
                });
            });
        });
        
    </script>
}
